package edu.columbia.cloudbox.io;

public class FileType implements Comparable<FileType> {

	private String name;

	private boolean isFolder;

	private String type;

	private String key;

	private long size;

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public long getSize() {
		return size;
	}

	public void setSize(long size) {
		this.size = size;
	}

	public FileType(String name, boolean isFolder, String type) {
		this.name = name;
		this.isFolder = isFolder;
		this.type = type;
	}

	public FileType(String name, boolean isFolder, String type, String key) {
		this(name, isFolder, type);
		this.key = key;
	}

	public FileType(String name, boolean isFolder, String type, String key,
			long size) {
		this(name, isFolder, type, key);
		this.size = size;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isFolder() {
		return isFolder;
	}

	public void setFolder(boolean isFolder) {
		this.isFolder = isFolder;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return this.name + ": " + this.type + ", " + key + "," + size;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null || !(o instanceof FileType)) {
			return false;
		}

		FileType fileType = (FileType) o;

		if (fileType.isFolder() == isFolder
				&& fileType.getName().equals(this.name)) {
			if (isFolder) {
				return true;
			} else if (fileType.getType().equals(type)) {
				return true;
			}
		}

		return false;
	}

	@Override
	public int compareTo(FileType fileType) {
		if (this.isFolder != fileType.isFolder) {
			if (this.isFolder) {
				return -1;
			}

			return 1;
		}

		if (fileType.getName().compareTo(name) < 0) {
			return 1;
		} else if (fileType.getName().compareTo(name) > 0) {
			return -1;
		}

		return 0;
	}

}
